<%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 20-2-19
  Time: 下午6:52
  To change this template use File | Settings | File Templates.
--%>
<%@page import="java.sql.*"%>
<%request.setCharacterEncoding("utf-8"); %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录验证</title>
</head>
<body>
<%
    Statement stmt =null;
    ResultSet rs = null;
    Connection con = null;
    //指向数据库client
    String url = "jdbc:MySQL://localhost:3306/client?&useSSL=false&serverTimezone=UTC";
    String dbusername = "root";  //数据库用户名
    String dbpassword = "123456";
    String name = request.getParameter("name").trim();
    String password = request.getParameter("password").trim();
    try{
        Class.forName("com.mysql.jdbc.Driver");  ////加载数据库驱动
       //数据库用户密码
        con = DriverManager.getConnection(url, dbusername, dbpassword);  //连接数据库
        stmt = con.createStatement();
        rs=stmt.executeQuery("select * from user where username='"+name+"'");
        if(rs.next()){
            rs=stmt.executeQuery("select * from user where username='"+name+"' and password='"+password+"'");
            if(rs.next()){
                out.println("登录成功");
                out.println(         );
                out.print("连接<a href=\"Connection.jsp\">服务器</a>");
            }else{
                out.print("密码输入错误！！！<br>"+"重新<a href=\"Login.jsp\">登录</a>");
            }
        }else{
            out.print("<font color=red>"+name+"</font>用户不存在！！！<br>"+"请点击<a href=\"index.jsp\">注册</a>");
        }
    }catch(Exception e){
        out.print(e);
    }finally{
        if(rs!=null)
            rs.close();
        if(stmt!=null)
            stmt.close();
        if(con!=null)
            con.close();
    }
%>
</body>
</html>
